﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;

namespace EvidenceManagement.Data
{
    public class SecurityDataAccessor : BaseDataAccessor
    {
        public SecurityDataAccessor(string connectionKey)
            : base(connectionKey)
        {

        }

        public StringBuilder GetSystemUserSValue(Guid systemUserID)
        {
            StringBuilder svalue = new StringBuilder();

            using (var command = DataRepository.CreateCommand(CommandType.StoredProcedure, SecurityStoredProcedures.GetSystemUserSValue))
            {
                DataRepository.AddCommandParameter(command, "SystemUserID", DbType.Guid, systemUserID);
                object result = DataRepository.ExecuteScalar(command);
                svalue = new StringBuilder(ConversionHelper.GetString(result));
            }

            return svalue;
        }

        public Guid GetSystemUserIDByUserName(string userName)
        {
            Guid systemUserID = Guid.Empty;

            using (var command = DataRepository.CreateCommand(CommandType.StoredProcedure, SecurityStoredProcedures.GetSystemUserIDByUserName))
            {
                DataRepository.AddCommandParameter(command, "userName", DbType.String, userName);
                object result = DataRepository.ExecuteScalar(command);
                systemUserID = ConversionHelper.GetGuid(result);
            }
            return systemUserID;
        }
    }
}
